import { useEffect } from "react";
import { useReactive } from "ahooks";
import { useModel } from "umi";

function personInfoModel() {
    const { remoteData } = useModel("global");

    let state = useReactive({
        baseInfo: {},
        loginInfo: {},
        settings: {},
        identity: "guest", // 当前用户身份：guest 游客(未登录); localLogined  本地登录; remoteLogined 公共认证中心登录; temporaryLogined 公共认证中心临时登录
    });

    useEffect(() => {
        const remotePersonInfo = remote.getGlobal("personInfo");
        for (let key in remotePersonInfo) {
            state[key] = remotePersonInfo[key];
        }
    }, []);

    const setPersonStateValue = (obj) => {
        for (let key in obj) {
            state[key] = obj[key];
        }
    };

    // const graphqlFetch = async (params, serviceName = "public") => {
    //     if (window.organizationUuid) {
    //         return await remoteData({
    //             object: "multi-organization-gateway",
    //             serviceName: `/graphql/${serviceName}_graphql_service`,
    //             params,
    //         });
    //     }
    // };

    return {
        ...state,
        setPersonStateValue,
    };
}

export default personInfoModel;
